package com.zdft.promotion.rabbitmq;

import com.zdft.promotion.rabbitmq.domain.QueueEnum;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfig {
    /**
     * 客户推送消息所绑定的交换机
     *
     * @return
     */
    @Bean
    DirectExchange orderUpdateExchange() {
        return (DirectExchange) ExchangeBuilder
                .directExchange(QueueEnum.ORDER_UPDATE.getExchange())
                .build();
    }

    /**
     * 创建客户推送的消息队列
     *
     * @return
     */
    @Bean
    public Queue orderUpdateQueue() {
        return new Queue(QueueEnum.ORDER_UPDATE.getName());
    }

    /**
     * 将客户消息队列和客户交换机绑定
     *
     * @param orderUpdateExchange
     * @param orderUpdateQueue
     * @return
     */
    @Bean
    Binding orderUpdateBinding(DirectExchange orderUpdateExchange, Queue orderUpdateQueue) {
        return BindingBuilder.bind(orderUpdateQueue)
                .to(orderUpdateExchange)
                .with(QueueEnum.ORDER_UPDATE.getRouteKey());
    }

    /**
     * 入库单推送消息所绑定的交换机
     *
     * @return
     */
    @Bean
    DirectExchange receiptsExchange() {
        return (DirectExchange) ExchangeBuilder
                .directExchange(QueueEnum.RECEIPTES_PUSH.getExchange())
                .build();
    }

    /**
     * 创建入库单推送的消息队列
     *
     * @return
     */
    @Bean
    public Queue receiptsQueue() {
        return new Queue(QueueEnum.RECEIPTES_PUSH.getName());
    }

    /**
     * 将入库单消息队列和客户交换机绑定
     *
     * @param receiptsExchange
     * @param receiptsQueue
     * @return
     */
    @Bean
    Binding receiptsBinding(DirectExchange receiptsExchange, Queue receiptsQueue) {
        return BindingBuilder.bind(receiptsQueue)
                .to(receiptsExchange)
                .with(QueueEnum.RECEIPTES_PUSH.getRouteKey());
    }

    /**
     * 客户推送消息所绑定的交换机
     *
     * @return
     */
    @Bean
    DirectExchange deliveryPushExchange() {
        return (DirectExchange) ExchangeBuilder
                .directExchange(QueueEnum.DELIVERY_PUSH.getExchange())
                .build();
    }

    /**
     * 创建客户推送的消息队列
     *
     * @return
     */
    @Bean
    public Queue deliveryPushQueue() {
        return new Queue(QueueEnum.DELIVERY_PUSH.getName());
    }

    /**
     * 将客户消息队列和客户交换机绑定
     *
     * @param deliveryPushExchange
     * @param deliveryPushQueue
     * @return
     */
    @Bean
    Binding deliveryPushBinding(DirectExchange deliveryPushExchange, Queue deliveryPushQueue) {
        return BindingBuilder.bind(deliveryPushQueue)
                .to(deliveryPushExchange)
                .with(QueueEnum.DELIVERY_PUSH.getRouteKey());
    }

    /**
     * 调拨推送消息所绑定的交换机
     *
     * @return
     */
    @Bean
    DirectExchange transfersPushExchange() {
        return (DirectExchange) ExchangeBuilder
                .directExchange(QueueEnum.TRANSFERS_PUSH.getExchange())
                .build();
    }

    /**
     * 创建调拨推送的消息队列
     *
     * @return
     */
    @Bean
    public Queue transfersPushQueue() {
        return new Queue(QueueEnum.TRANSFERS_PUSH.getName());
    }

    /**
     * 将调拨消息队列和客户交换机绑定
     *
     * @param transfersPushExchange
     * @param transfersPushQueue
     * @return
     */
    @Bean
    Binding transfersPushBinding(DirectExchange transfersPushExchange, Queue transfersPushQueue) {
        return BindingBuilder.bind(transfersPushQueue)
                .to(transfersPushExchange)
                .with(QueueEnum.TRANSFERS_PUSH.getRouteKey());
    }

    /**
     * 调拨明细推送消息所绑定的交换机
     *
     * @return
     */
    @Bean
    DirectExchange transfersDetailPushExchange() {
        return (DirectExchange) ExchangeBuilder
                .directExchange(QueueEnum.TRANSFERS_DETAIL_PUSH.getExchange())
                .build();
    }

    /**
     * 创建调拨明细推送的消息队列
     *
     * @return
     */
    @Bean
    public Queue transfersDetailPushQueue() {
        return new Queue(QueueEnum.TRANSFERS_DETAIL_PUSH.getName());
    }

    /**
     * 将调拨明细消息队列和客户交换机绑定
     *
     * @param transfersDetailPushExchange
     * @param transfersDetailPushQueue
     * @return
     */
    @Bean
    Binding transfersDetailPushBinding(DirectExchange transfersDetailPushExchange, Queue transfersDetailPushQueue) {
        return BindingBuilder.bind(transfersDetailPushQueue)
                .to(transfersDetailPushExchange)
                .with(QueueEnum.TRANSFERS_DETAIL_PUSH.getRouteKey());
    }

    /**
     * 批次信息推送消息所绑定的交换机
     *
     * @return
     */
    @Bean
    DirectExchange transfersBatchPushExchange() {
        return (DirectExchange) ExchangeBuilder
                .directExchange(QueueEnum.TRANSFERS_BATCH_PUSH.getExchange())
                .build();
    }

    /**
     * 创建批次信息推送的消息队列
     *
     * @return
     */
    @Bean
    public Queue transfersBatchPushQueue() {
        return new Queue(QueueEnum.TRANSFERS_BATCH_PUSH.getName());
    }

    /**
     * 将批次信息消息队列和客户交换机绑定
     *
     * @param transfersBatchPushExchange
     * @param transfersBatchPushQueue
     * @return
     */
    @Bean
    Binding transfersBatchPushBinding(DirectExchange transfersBatchPushExchange, Queue transfersBatchPushQueue) {
        return BindingBuilder.bind(transfersBatchPushQueue)
                .to(transfersBatchPushExchange)
                .with(QueueEnum.TRANSFERS_BATCH_PUSH.getRouteKey());
    }

    /**
     * 缺货记录信息推送消息所绑定的交换机
     *
     * @return
     */
    @Bean
    DirectExchange transfersLackPushExchange() {
        return (DirectExchange) ExchangeBuilder
                .directExchange(QueueEnum.TRANSFERS_LACK_PUSH.getExchange())
                .build();
    }

    /**
     * 创建缺货记录信息推送的消息队列
     *
     * @return
     */
    @Bean
    public Queue transfersLackPushQueue() {
        return new Queue(QueueEnum.TRANSFERS_LACK_PUSH.getName());
    }

    /**
     * 将缺货记录信息消息队列和客户交换机绑定
     *
     * @param transfersLackPushExchange
     * @param transfersLackPushQueue
     * @return
     */
    @Bean
    Binding transfersLackPushBinding(DirectExchange transfersLackPushExchange, Queue transfersLackPushQueue) {
        return BindingBuilder.bind(transfersLackPushQueue)
                .to(transfersLackPushExchange)
                .with(QueueEnum.TRANSFERS_LACK_PUSH.getRouteKey());
    }
}
